clc
clear
f = 262;%C调声音频率
Fs = 8000;%采样频率
N = 300;
T = 0:1/Fs:1.5-1/Fs;%声音持续1.5秒
Amp = [1 0 1/3 0 1/5 0 1/7 0 1/9 0]/pi;%高阶和弦振幅
Ph = (pi/2)*ones(1,10);%高阶和弦相位

sound_c = sin(2*pi*f*T );%原始声音信号
sum_harmon = zeros(1,length(T));%和弦声音之和
for K = 1:10
    sound_harmon = Amp(K)*sin(2*pi*f*K*T+ Ph(K));%K阶和弦
    sum_harmon = sum_harmon + sound_harmon;
end
for i = 1:3
    if i == 1
        subplot(3,1,1)
        stem(T(1:N),sound_c(1:N))%前N个采样
        sound(sound_c,Fs);%以采样频率播放声音
    end
    if i == 2
        subplot(3,1,2)
        stem(T(1:N),sum_harmon(1:N))%前N个采样
        sound(sum_harmon,Fs);%以采样频率播放声音
    end
    if i == 3
        subplot(3,1,3)
        stem(T(1:N),sound_c(1:N) + sum_harmon(1:N))%前N个采样
        sound(sound_c + sum_harmon,Fs);%以采样频率播放声音
    end
    pause(0.3);%暂停0.3秒
end
